<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
	<head> 
		<meta charset="utf-8" /> 
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
		<meta name="renderer" content="webkit"/>
		<link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css" />
		<link rel="stylesheet" type="text/css" href="../../css/common.css" />
		<link rel="stylesheet" type="text/css" href="../../css/welcome.css" />
		<link rel="stylesheet" type="text/css" href="../../css/joyride-2.1.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/print.css" media="print" />
		<script type="text/javascript" src="../../js/jquery-1.8.3.min.js" ></script>
		<script type="text/javascript" src="../../js/common.js"> </script>
		<script type="text/javascript" src="../../js/jquery.jqprint-0.3.js" ></script>
		<title>祥利百悦</title> 
	</head> 
	<body>
		<!--遮罩层-->
		<div class="zhy_zhezhao_pop " style="height: 800px; display: none;"></div>
		<!--遮罩层 end-->
		<div class="zhy_popa zhy_popa_cancel " style="width: 450px;margin-left: -225px;display: none;">
			<p class="color66">提示<span class="pull-right close_icon" onclick="hidePopC()"></span></p>
		  	<div class="pop_content">
			    <p>确定要删除所选数据吗?</p>
			  	<div class="operate_btn pull-right"> 
			  	    <button type="button" class="btn cancle_yes">确定</button>
			        <button type="button" class="btn cancle_btn" onclick="hidePopC()">取消</button>
			  	</div>
		  	</div>
		</div>
		<!--遮罩层 end-->
		<!--遮罩层-->
		<div class="zhy_popa dialog_2 " style="width: 350px;margin-left: -175px;display: none;">
			<div class="pop_content text-center">
				 <div class="panel-body bgLineXie" style="padding: 0px 0px;" id="printContent">
					<img src="../../img/loading_load.gif" width="100%" id="qrCode"/>
				</div>
				<div class="operate_btn mt10"> 
			  	    <button type="button" class="btn cancle_yes" onclick="goPrint()">打&nbsp;印</button>
			        <button type="button" class="btn cancle_btn mr0" onclick="hidePopC()">取消</button>
			  	</div>
			</div>
		</div>
		<div class="main_content member_list" >
			<div class="col-xs-12 col-sm-12 div_bordered"> 
		  		<div class="panel panel-default">
			   		<div class="panel-heading">
			   			<div class="jkbg_title_boxa">
							<h4>长者信息</h4>
						</div>
				    	<form class="form-inline pl20" role="form">
				    	   	<input type="hidden" id="serverStationCode" value="${serverStationCode}">
				    	   	<input type="hidden" id="searchState" value="${searchState }"/>
				    	   	<div class="form-group">证件类型：
	    	   				</div>
						   	<div class="form-group">
								<jsp:include page="../../common/split_page_search_plugin.jsp"/>
						   	</div>
						</form>
		      		</div>
					<table class="table table-bordered  table-hover "> 
						<thead > 
							<tr> 
								<th width="12%">长者姓名</th> 
								<th width="9%">性别</th> 
								<th width="9%">年龄</th> 
								<th width="13%">手机号码</th>
								<th width="18%">入住状态</th>
								<th width="10%">查看二维码</th>
								<th width="12%">身份证</th>
								<th >操作</th>
							</tr> 
						</thead> 
						<tbody id="member_show">
                            <c:forEach items="${allMembers}" var="member">
                                <tr>
                                    <td>${member.name}</td>
                                    <td>${member.sex==1?"男":"女"} </td>
									<td>${allAges[member.memberId]} </td>
                                    <td>${member.phone}</td>
									<td><c:forEach items="${allMemberStates}" var="state">
										<c:if test="${state.memberId==member.memberId}">
											${state.checkState==0?"未入住":(state.checkState==1?"已入住":"退住")}
										</c:if>
									</c:forEach></td>
                                    <td><a href="javascript:showQRcode('${member.memberId}','${member.serverStationCode}');" class="colorblue" style="text-decoration:none;">查看</a></td>
                                    <td>${member.postionNumber}</td>
                                    <td>
                                        <zhyAuth:hasPermission name="mem:mem_manage">
                                            <span  class="colorblue"><a href="member_show.action?memberId=${member.memberId}" class="colorblue">详情</a></span>
                                            <span class="colorblue edit"><a href="member_update.action?memberId=${member.memberId}" class="colorblue">修改</a></span>
                                            <span class="colorblue edit">
												<c:forEach items="${allMemberStates}" var="state">
													<c:if test="${state.memberId==member.memberId}">
														<c:if test="${state.checkState==1}"><a href="../live/live_one.html" class="colorblue">退住</a></c:if>
														<c:if test="${state.checkState!=1}"><a href="../live/back_live_add.html" class="colorblue">入住</a></c:if>
													</c:if></c:forEach>
											</span>
                                            <span class="colorred delete" value="${member.memberId}" name="${member.name}" onclick="javascript:showPopC('zhy_popa_cancel');">删除</span>
                                        </zhyAuth:hasPermission>
                                        <c:if test="${i.index == 0}"><input id="total" type="hidden" value="${total}"/></c:if>
                                    </td>
                                </tr>
                        </c:forEach>
						</tbody>
					</table>
	        	</div>
				<div id="splitBarDiv" class="row text-center">
					<jsp:include page="../../common/split_page_bar_plugin.jsp"/>
				</div>
	   		</div>
	  	</div>
		<div id="del_dialog">
		</div>
		<div id="active_dialog">
		</div>
		<ol id="joyRideTipContent">
	    	<li data-class="so-awesome2" data-button="我知道了" >
	        	<p>点击此处可添加新长者</p>
	      	</li>
	    </ol>
		<script type="text/javascript" src="../../js/jquery.pagination.js" ></script>
		<script type="text/javascript" src="../../js/jquery.cookie.js" charset="utf-8"></script>
		<script type="text/javascript" src="../../js/jquery.joyride-2.1.js"></script> <!--向导 -->
		<script type="text/javascript" src="../../js/ajaxExcelDownload.js"></script>
		<script type="text/javascript" src="../../js/jquery.placeholder.js" charset="utf-8"></script><!-- placehoder兼容 -->
		<!--[if lt IE 10]>
			<script type="text/javascript">
				$(function() {
				      $('input, textarea').placeholder({force: true});
				});
			</script>
		<![endif]-->
		<script type="text/javascript">
	        var pageIndex = 0;     //页面索引初始值  
	        var pageSize = 10;     //每页显示条数初始化，修改显示条数，修改这里即可  
	        var total = 0;
	        $(function(){
	        	/* if($("a:contains('普通长者')").length == 0){
	        		$(".dropdown-menu").append('<li><a value="-1" href="javascript:InitTable(0);">普通长者</a></li>');
	        	} */
	        	
				//页面搜索调用
				$("#member_search").click(function(){
					showPopC("dialog_1");
					//$("#keyWord")[0].focus();
					idCardMsgRead();
					setTimeout("InitTable(0)",1000);
				});
				
				document.onkeydown = keydown;
				function keydown(e){
					var currKey = 0, e = e || event;
					currKey = e.keyCode || e.which || e.charCode;// 支持IE、FF
					if (currKey == 13) {
						$("#member_search").click();
					}
				}


				$("#member_export").click(function(){
					exportToExcel();
				});
	        });

	        function initPage(pageIndex, pageSize, total){
	        	$("#member_pagination").pagination(total, {  
	        	    callback: function(){return true;},
	        	    link_to: "javascript:InitTable(__id__)",
	        	    prev_text: '上一页',       //上一页按钮里text  
	        	    next_text: '下一页',       //下一页按钮里text
	        	    items_per_page: pageSize,  //显示条数  
	        	    num_display_entries: 6,    //连续分页主体部分分页条目数  
	        	    current_page: pageIndex - 1,   //当前页索引  
	        	    num_edge_entries: 2        //两侧首尾分页条目数  
	        	});  
	        }
	        
	        //请求数据  
	        	        // 删除长者调用===返回页面
	        function del_member_jsp(t){
	        	$.ajax({
	        		type: "POST",
	        		dataType: "html",
	        		url: "${ctx}/member/del_member_jsp",
	        		data:{
	        			memberId: $(t).attr("value"),
	        			name: $(t).attr("name")
	        		},
	        		success : function(data) {
        				$("#del_dialog").empty().html(data);
        				showPopC('deletepop');
	        		}
	        	});
	        }

	        //删除长者操作
	        function del_member(){
	        	$.ajax({
	        		type : "post",
	        		dataType: "json",
	        		url : "${ctx}/member/del_member",
	        		data:{
	        			memberId: $("#del_member_id").val(),
	        			station: $("#serverStationCode").val()

	        		},
	        		success : function(data) {
	        			if(data.resultCode === "SUCC" && data.data){
	        				hidePopC();
	        				window.location = "${ctx}/member/get_member_list";
	        			}else{
	        				zhyAlert("删除失败");
	        				hidePopC();
	        			}
	        		}
	        	});
	        }
	        
	        function exportToExcel(){
	        	var serverStationCode = $("#serverStationCode").val();
	        	var keyWord = $("#keyWord").val();
	        	//var memberLevel = $("#memberLevel .dropdown-text").attr("value");
	        	var idType = $("#idType .dropdown-text").attr("value");
	        	if(keyWord != null && keyWord != "" && keyWord.length > 0){
	        		keyWord = "%" + keyWord + "%";
	        	}
	        	
	        	showPopC("export_waiting");
	        	window.parent.WS.listen("export_excel_" + serverStationCode, callback);
	        	$.ajaxExcelDownload({
			        url: "${ctx}/member/export", 
			        data:{
			        	serverStationCode: serverStationCode,
			        	keyWord: keyWord,
			        	//memberLevel: memberLevel,
			        	IDType: idType,
			        	grade: 1,
			        	state: 1
			        },
			        secureuri: false, //一般设置为false
			        dataType:"json",
			       	success: function (data, status){
			            downloadCallBack(data);
			        }
	        	});
	        }
	        
	        function downloadCallBack(data){
	        	if(data.resultCode === "FAIL"){
	        		zhyAlert(data.failureMessage);
	        		hidePopC();
	        	}
	        }
	        
	        function callback(data){
	        	hidePopC();
	        }
	        
	      //身份证信息读取
			function idCardMsgRead(){
				$.ajax({
					type: "get",
		            async: false,
					dataType: "jsonp",
					url: "http://127.0.0.1:21250/api/hsidcard",
					jsonp: "callback",
					timeout: 5000,
					success:function(json){
						if(json.state == 1){
							$("#keyWord").val(json.data.idCard);
							
							InitTable(0);
						}
					}
				});
			}
			
			//查看二维码
			function showQRcode(memberId,serverStationCode){
				<!-- var jsonObj =  jQuery.parseJSON(data); -->
			    		var apptype = "../../img/1529390159.png";
			    		$("#qrCode").attr("src","");
			    		$("#qrCode").attr("src",apptype);
			    		showPopC('dialog_2');
						
						
				$.ajax({   
			        type: "POST",  
			        dataType: "html",  
			        url: '${ctx}/memberQRcode/create_QRcode',      //提交到一般处理程序请求数据  
			        data: {
			        	memberId:memberId,
			        	serverStationCode:serverStationCode,
			        },  
			        success: function(data) { 
			        	var jsonObj =  jQuery.parseJSON(data);
			    		var apptype = jsonObj.QrCodeUrl;
			    		$("#qrCode").attr("src","");
			    		$("#qrCode").attr("src",apptype);
			    		showPopC('dialog_2');
			        }  
			    });        
			}
			
			//打印
	        function goPrint(){
	        	$("#printContent").jqprint();
	        }
			 
		</script>
	</body>

</html>